<?php include_once('header.php');?>
	<div class="main-content">
		<div class="breadcrumbs" id="breadcrumbs">
			<script type="text/javascript">
				try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
			</script>
			<ul class="breadcrumb">
				<li><a href="/admin/welcome"><i class="icon-home home-icon"></i>首页</a></li>
				<li><a href="/admin/branch/branch_list">网点管理</a></li>
				<li><a href="/admin/branch/branch_list">网点列表</a></li>
				<li>增加信息</li>
			</ul>
		</div>
		<div class="page-content" style="margin-top:18px;">			
			<div class="row">
				<div class="col-xs-12">
					<div style="border:1px solid #e1e1e1;">
						<div style="height:50px;"><span style="background-color:#f9f9f9;width:100px; height:40px; display:inline-block;*display:inline;*zoom; border:1px solid #e2e2e5; line-height:40px;color:#666; text-align:center;"><b>基本信息</b></span></div>				
						<form class="form-horizontal" enctype="multipart/form-data" role="form" method="post" action="/admin/branch/add"  onsubmit="return check()">				
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">网点名称</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="name" name="name" value="">
								</div>
							</div>
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">网点类型</label>
								<div class="col-sm-2">
									<select name="form" id="form">
										<option value="1">正常</option>
										<option value="2">旗下</option>																					
									</select>
								</div>
							</div>																									
							<div class="form-group">
				                <label  class="col-sm-1 control-label">网点图片</label>
				                <div class="col-sm-3">
				                	<input type="hidden" class="form-control" name="b_image" value="">
				                    <input id="file-0b" class="file" type="file" name="jietu">                    
				                </div>
				             </div>						
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">销售彩种:</label>
								<div class="col-sm-3">
									<input type="text" class="form-control"id="pname" name="type" value="" />
								</div><b style="margin-top:10px;line-height:54px;">点击下面彩种列表</b>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">彩种列表:</label>
								<div class="blogTs blogTs_tit col-sm-4" id="articleTagList"><div class="closex"></div>
									<div class="ts"></div>
									<table class="blogTsTbl">
										<tbody>
											<th>列表：</th><td id="hotTagList"></td>
										</tbody>
									</table>
								</div>					
							</div>					
							<div class="form-group">
				                <label  class="col-sm-1 control-label">分佣比例</label>
				                <div class="col-sm-2">
				                	<input type="text" class="form-control" id="scale" name="scale" value="">              
				                </div><b style="margin-top:10px;line-height:34px;">%</b>
				             </div> 
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">联系人</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="contact" name="contact" value="">
								</div>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">联系人电话</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="contact_num" name="contact_num" value="">
								</div>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">卡归属银行</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="bank_name" name="bank_name" value="">
								</div>
							</div>		
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">银行卡帐号</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="bank_num" name="bank_num" value="">
								</div>
							</div>		
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">收款人</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="receiver_name" name="receiver_name" value="">
								</div>
							</div>		
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">QQ</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="qq" name="qq" value="">
								</div>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">微信</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="wechat" name="wechat" value="">
								</div>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">帐号</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="username" name="username" value="<?=$rand_username?>">
								</div>
							</div>	
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">密码</label>
								<div class="col-sm-2">
									<input type="text" class="form-control" id="password" name="password" value="<?=$rand_password?>">
								</div>
							</div>
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">网点地址</label>
								<div class="col-sm-4">				
									<select name="province" id="province">
										<?php 
											foreach($area_list as $key => $value) {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'">'.$value['areaname'].'</option>';																					
											}				
										?>
									</select>						 
									<select name="city" id="city">						 
										<?php 
											foreach($city_list as $key => $value) {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'">'.$value['areaname'].'</option>';									
											}										
										?>
									</select>					 
									<select name="county" id="county">							  
										<?php 
											foreach($county_list as $key => $value) {
												echo ' <option value="'.$value['areano'].','.$value['areaname'].'">'.$value['areaname'].'</option>';																	
											}		
										?>
									</select>
								</div>							
							</div>
							<input id="company_address" name="company_address" type="hidden" value=""/>
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">详细地址</label>
								<div class="col-sm-3">
									<input type="text" id="company_address_detail" onclick="lag();" onchange="lag();"  class="form-control" name="address" value="">
								</div>
							</div>
							<div class="form-group">
								<label for="title" class="col-sm-1 control-label">经纬度</label>
								<div class="col-sm-6">
									<input name="longitude" id="longitude" type="text" class="w200" value=""/>&nbsp;&nbsp;纬度&nbsp;&nbsp;<input name="latitude" id="latitude" type="text" class="w200" value=""/>
								</div>
							</div>
						 	<div class="form-group">
						   		<div class="col-sm-offset-1 col-sm-10">
									<button type="submit" id="submit" class="btn btn-primary">提交保存</button>
									<button type="submit" id="cancel" class="btn btn-warning">返回上页</button>
								</div>
						  	</div>
						</form>	
					</div>
				</div>
			</div>					
		</div>													
	</div>
<?php include_once('content.php');?>
	<link href="/public_source/www/assets/css/ace.min.css" rel="stylesheet" />	
	<link href="/public_source/www/assets/css/jquery.tag-editor.css" rel="stylesheet"/>
	<link href="/public_source/www/assets/css/fileinput.css" rel="stylesheet" type="text/css" />
	<link  rel="stylesheet" href="/public_source/www/assets/css/jquery-confirm.css" />
	<link  rel="stylesheet" href="/public_source/www/css/confirm.css" />
	<link href="/public_source/www/css/tag.css" rel="stylesheet"/>
    <script src="/public_source/www/assets/js/bootbox.min.js"></script>
    <script src="/public_source/www/assets/js/fileinput.js" type="text/javascript"></script> 
	<script src="/public_source/www/assets/js/jquery.tag-editor.min.js"></script>
	<script src="/public_source/www/assets/js/jquery-confirm.js"></script>
	<script src="/public_source/www/js/areas.js"></script>
	<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=FlY5NaGtMRq328c6uSycmgVg"></script>
<?php include_once('footer.php');?>	
<script type="text/javascript">
	$(document).ready(function(){
		$("#cancel").click(function() {
			window.location.replace('/admin/branch/branch_list');
			return false;
		});
	});
	function check() {
		var name = document.getElementById("name").value;
	   	var scale = document.getElementById("scale").value;
	   	var bank_num = document.getElementById("bank_num").value;
		var bank_name = document.getElementById("bank_name").value;
		var receiver_name = document.getElementById("receiver_name").value;
		var username = document.getElementById("username").value;
		var password = document.getElementById("password").value;
	   	var temp=/^\d+(\.\d+)?$/;
	   	var data = {name:name};
	   	var user_data = {username:username};
	   	var bool = true;
		if(!name) {
			$.alert({
			    title: '提示',
			    content:'网点名称不能为空',
			    confirm: function(){
			    }
			});
			return false;
		}
	   	if(scale <= 0 || scale > 100 || !temp.test(scale)) {
			$.alert({
			    title: '提示',
			    content:'分佣比例格式有误',
			    confirm: function(){
			    }
			});
			return false;			
		}
		if(!bank_name) {
			$.alert({
			    title: '提示',
			    content:'所属银行不能为空',
			    confirm: function(){
			    }
			});
			return false;
		}
		if(!luhmCheck(bank_num) || !bank_num) {
			$.alert({
			    title: '提示',
			    content:'银行卡号错误',
			    confirm: function(){
			    }
			});
			return false;
		}
		if(!receiver_name) {
			$.alert({
			    title: '提示',
			    content:'收款人不能为空',
			    confirm: function(){
			    }
			});
			return false;
		}
		if(!username) {
			$.alert({
			    title: '提示',
			    content:'帐号不能为空',
			    confirm: function(){
			    }
			});
			return false;
		}
		if(!password) {
			$.alert({
			    title: '提示',
			    content:'密码不能为空',
			    confirm: function(){
			    }
			});
			return false;
		}
	   $.ajax({
			url:"/admin/branch/check_sole",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
		if(!bool) {
		   	$.alert({
			    title: '提示',
			    content:'网点名已存在',
			    confirm: function(){
			    }
			});
			 return false;	
		}
	   $.ajax({
			url:"/admin/branch/check_sole",
			async: false,
			type:"post",
			data: user_data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
		if(!bool) {
		   	$.alert({
			    title: '提示',
			    content:'帐号已存在',
			    confirm: function(){
			    }
			});
			 return false;	
		}
	   	return true;
	}
	
	function luhmCheck(bankno){
	    var lastNum=bankno.substr(bankno.length-1,1);//取出最后一位（与luhm进行比较）
	 
	    var first15Num=bankno.substr(0,bankno.length-1);//前15或18位
	    var newArr=new Array();
	    for(var i=first15Num.length-1;i>-1;i--){    //前15或18位倒序存进数组
	        newArr.push(first15Num.substr(i,1));
	    }
	    var arrJiShu=new Array();  //奇数位*2的积 <9
	    var arrJiShu2=new Array(); //奇数位*2的积 >9
	     
	    var arrOuShu=new Array();  //偶数位数组
	    for(var j=0;j<newArr.length;j++){
	        if((j+1)%2==1){//奇数位
	            if(parseInt(newArr[j])*2<9)
	            arrJiShu.push(parseInt(newArr[j])*2);
	            else
	            arrJiShu2.push(parseInt(newArr[j])*2);
	        }
	        else //偶数位
	        arrOuShu.push(newArr[j]);
	    }
	     
	    var jishu_child1=new Array();//奇数位*2 >9 的分割之后的数组个位数
	    var jishu_child2=new Array();//奇数位*2 >9 的分割之后的数组十位数
	    for(var h=0;h<arrJiShu2.length;h++){
	        jishu_child1.push(parseInt(arrJiShu2[h])%10);
	        jishu_child2.push(parseInt(arrJiShu2[h])/10);
	    }        
	     
	    var sumJiShu=0; //奇数位*2 < 9 的数组之和
	    var sumOuShu=0; //偶数位数组之和
	    var sumJiShuChild1=0; //奇数位*2 >9 的分割之后的数组个位数之和
	    var sumJiShuChild2=0; //奇数位*2 >9 的分割之后的数组十位数之和
	    var sumTotal=0;
	    for(var m=0;m<arrJiShu.length;m++){
	        sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
	    }
	     
	    for(var n=0;n<arrOuShu.length;n++){
	        sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
	    }
	     
	    for(var p=0;p<jishu_child1.length;p++){
	        sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
	        sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
	    }      
	    //计算总和
	    sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
	     
	    //计算Luhm值
	    var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;        
	    var luhm= 10-k;
	     
	    if(lastNum==luhm){
	    	return true;
	    }
	    else{
	    	return false;
	    }        
	} 		
</script>
<script type="text/javascript">
    function ditu(address){
        $("#demo").html('123');
	// 百度地图API功能
	var map = new BMap.Map("demo");
	var point = new BMap.Point(116.331398,39.897445);
	map.centerAndZoom(point,15);
	// 创建地址解析器实例
	var myGeo = new BMap.Geocoder();
	// 将地址解析结果显示在地图上,并调整地图视野
	myGeo.getPoint(address, function(point){
		if (point) {
                        $("#latitude1").val(point.lat);
                        $("#longitude1").val(point.lng);
                        $("#latitude").val(point.lat);
                        $("#longitude").val(point.lng);
			map.centerAndZoom(point, 15);
                        var marker = new BMap.Marker(point); // 创建标注 
                        map.addControl(new BMap.NavigationControl());
                        map.addOverlay(marker);
                        map.panBy(305,165);
                        marker.enableDragging();
                        //标注拖拽后的位置
                        marker.addEventListener("dragend", function (e) {
                            $("#latitude1").val(e.point.lat);
                            $("#longitude1").val(e.point.lng);
                           
                        });
                }else{
                        alert("您选择地址没有解析到结果!请手动设置");
                }
	}, "杭州市");
    }
    function close_div(){
        $("#latitude").val($("#latitude1").val());
        $("#longitude").val($("#longitude1").val());
        document.getElementById('light').style.display='none';document.getElementById('fade').style.display='none'; 
        
    }
    function lag(){
        var address=$("#company_address").val()+$("#company_address_detail").val();
        var myGeo = new BMap.Geocoder();
        myGeo.getPoint(address, function(point){
            if (point) {
                $("#latitude").val(point.lat);
                $("#longitude").val(point.lng);
            }
        },'杭州市');
    }
    function open_div(){
        var address= $("#company_address").val()+$("#company_address_detail").val();       
        if(!(address)){
            alert('请先选择地区');exit;
        }
        ditu(address);
        document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block';
    }   
</script>